// CameraPlaneControl.cpp : implementation file
//

#include "stdafx.h"
#include "CG_skel_w_MFC.h"
#include "CameraPlaneControl.h"
#include "afxdialogex.h"


// CameraPlaneControl dialog

IMPLEMENT_DYNAMIC(CameraPlaneControl, CDialogEx)

CameraPlaneControl::CameraPlaneControl(CWnd* pParent /*=NULL*/)
	: CDialogEx(CameraPlaneControl::IDD, pParent)
{
}

CameraPlaneControl::~CameraPlaneControl()
{
}

void CameraPlaneControl::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, YAW, yaw);
	DDX_Control(pDX, PITCH, pitch);
	DDX_Control(pDX, ROLL, roll);
	DDX_Control(pDX, IDC_CAMERA_NAME, cameraName);
}


BEGIN_MESSAGE_MAP(CameraPlaneControl, CDialogEx)
	ON_WM_SHOWWINDOW()
	ON_BN_CLICKED(IDOK, &CameraPlaneControl::OnBnClickedOk)
END_MESSAGE_MAP()

// CameraPlaneControl message handlers


void CameraPlaneControl::OnBnClickedOk()
{
	Camera *camera = m_scene->getActiveCamera();
	char buff[5];

	yaw.GetWindowTextA(buff, 5);
	int yaw_ang = atoi(buff);

	pitch.GetWindowTextA(buff, 5);
	int pitch_ang = atoi(buff);

	roll.GetWindowTextA(buff, 5);
	int roll_ang = atoi(buff);

	camera->yaw(yaw_ang);
	camera->pitch(pitch_ang);
	camera->roll(roll_ang);
	
	resetInput();

	m_scene->draw();

//	CDialogEx::OnOK();
}

void CameraPlaneControl::OnShowWindow(BOOL bShow, UINT nStatus) {
	resetInput();
}


void CameraPlaneControl::resetInput() {
	Camera *camera = m_scene->getActiveCamera();
	cameraName.SetWindowTextA(_T(camera->getName().c_str()));
	yaw.SetWindowTextA(_T("0"));
	pitch.SetWindowTextA(_T("0"));
	roll.SetWindowTextA(_T("0"));
}
